const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test', {useMongoClient: true});
/*在操控数据库之前我们最好检测数据库是否打开*/
const db = mongoose.connection;
/*检测数据库*/
db.on('error', function (err) {
    console.log(err);
})
/*检测数据库是否打开*/
db.once('open', function (err) {
    if (!err) {
        console.log('打开成功');
    } else {
        console.log('打开失败');
        return
    }

})
module.exports = mongoose;